package com.itqf.json;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.math.BigDecimal;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/10/10
 * @Time: 下午3:28
 */
public class MySerializer extends JsonSerializer<Double> {

    //Double aDouble  原值
    @Override
    public void serialize(Double aDouble, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        //保留两位小数  按照四舍五入规则
       String num =  BigDecimal.valueOf(aDouble).setScale(2,BigDecimal.ROUND_HALF_UP).toString()+"元";

       //写回客户端
        jsonGenerator.writeString(num);

    }
}
